View Javadoc

1   /*
2    * Copyright (c) 2004-2005, University Health Network.  All rights reserved. Distributed under the BSD 
3    * license (see http://opensource.org/licenses/bsd-license.php).
4    *  
5    * Created on 24-Nov-2004
6    */
7   package ca.uhn.cache.internal.hibernate.impl;
8   
9   import java.io.Serializable;
10  import java.sql.Timestamp;
11  import java.util.HashSet;
12  import java.util.Set;
13  
14  import ca.uhn.cache.CacheReasonEnum;
15  import ca.uhn.cache.IQuery;
16  import ca.uhn.cache.VolatilityEnum;
17  import ca.uhn.cache.impl.Chunk;
18  import ca.uhn.cache.internal.IChunk;
19  import ca.uhn.cache.internal.hibernate.HibernateCacheReasonEnum;
20  import ca.uhn.cache.internal.util.TimestampUtils;
21  
22  /***
23   * A block of data that is retrieved and cached together.  The 
24   * boundaries of a <code>IChunk</code> are defined according to 
25   * <code>QueryParameter</code>s.  Data items may have attributes 
26   * such as category, date, name, etc.  Some of these, for example 
27   * category and date, will correspond to <code>QueryParameter</code>s.
28   * A <code>IChunk</code> is a grouping of data items in the same part 
29   * of the <code>QueryParameter</code> space.  How this space is divided 
30   * is determined by a <code>ISemanticCache</code>.  
31   *  
32   * @hibernate.class table="chunk"
33   *  
34   * @author <a href="mailto:bryan.tripp@uhn.on.ca">Bryan Tripp</a>
35   * @version $Revision: 1.1 $ updated on $Date: 2005/01/24 22:52:40 $ by $Author: bryan_tripp $
36   */
37  public class ChunkField extends HibernateObject {
38  
39      private VolatilityEnum myVolatility;
40      private Timestamp myLastUpdateTime;
41      private Timestamp myCacheTime;
42      private Timestamp myLastAccessTime;
43      private Set myReasons = new HashSet();
44      private int myQueryHash;
45      private Timestamp myExpiryTime;
46      
47      private Serializable myBoundaries;
48      
49      /***
50       * Constructor
51       */
52      public ChunkField() 
53      {
54      }
55      
56      /***
57       * @return the greatest volatility of all data in the chunk 
58       *
59       * @hibernate.property type="ca.uhn.cache.internal.hibernate.HibernateVolatilityEnum"
60       */
61      public VolatilityEnum getVolatility()
62      {
63          return myVolatility;
64      }
65  
66      /***
67       * @param theVolatility the greatest volatility of all data in the chunk 
68       */
69      public void setVolatility(VolatilityEnum theVolatility)
70      {
71          myVolatility = theVolatility;
72      }
73          
74      /***
75       * @return the most recent time of update of all data in the chunk 
76       *
77       * @hibernate.property
78       */
79      public Timestamp getLastUpdateTime()
80      {
81          return myLastUpdateTime;
82      }
83  
84      /***
85       * @param theLastUpdateTime the most recent time of update of all data in the chunk 
86       */
87      public void setLastUpdateTime(Timestamp theLastUpdateTime)
88      {
89          myLastUpdateTime = theLastUpdateTime;
90      }
91  
92      /***    
93       * @return the time at which the data in the chunk were cached 
94       *
95       * @hibernate.property
96       */
97      public Timestamp getCacheTime()
98      {
99          return myCacheTime;
100     }
101 
102     /***    
103      * @param theCacheTime the time at which the data in the chunk were cached 
104      */
105     public void setCacheTime(Timestamp theCacheTime)
106     {
107         myCacheTime = theCacheTime;
108     }
109     
110     /***
111      * @return the most recent time at which data in the the chunk were accessed
112      *
113      * @hibernate.property
114      */
115     public Timestamp getLastAccessTime()
116     {
117         return myLastAccessTime;
118     }
119 
120     /***
121      * @param theLastAccessTime the most recent time at which data in the the chunk were accessed
122      */
123     public void setLastAccessTime(Timestamp theLastAccessTime)
124     {
125         myLastAccessTime = theLastAccessTime;
126     }
127     
128 
129     /***
130      * @return a list of reasons why this chunk was cached 
131      *
132      * @hibernate.set table="chunk_reason" cascade="all"
133      * @hibernate.collection-key column="chunk_id"
134      * @hibernate.collection-element 
135      *      type="ca.uhn.cache.internal.hibernate.HibernateCacheReasonEnum" 
136      *      column="reason"
137      *      length="50" 
138      *      not-null="true"
139      */
140     public Set getReasons()
141     {
142         return myReasons;
143     }
144 
145     /***
146      * @param theReasons  a list of reasons why this chunk was cached 
147      */
148     public void setReasons(Set theReasons)
149     {
150         myReasons = theReasons;
151     }
152     
153     /***
154      * @param theReason the reason to add
155      */
156     public void addReason(HibernateCacheReasonEnum theReason)
157     {
158         myReasons.add(theReason);
159     }
160 
161     /***
162      * @param theQueryHash the hash code for the query corresponding to this chunk
163      */
164     public void setQueryHash(int theQueryHash)
165     {
166         myQueryHash = theQueryHash;
167     }
168     
169     /***
170      * @return the hash code for the query corresponding to this chunk
171      *
172      * @hibernate.property
173      */
174     public int getQueryHash()
175     {
176         return myQueryHash;
177     }
178 
179     /***
180      * @return Returns the expityTime.
181      * 
182      * @hibernate.property
183      */
184     public Timestamp getExpiryTime() {
185         return myExpiryTime;
186     }
187     /***
188      * @param theExpityTime The expityTime to set.
189      */
190     public void setExpiryTime( Timestamp theExpityTime ) {
191         myExpiryTime = theExpityTime;
192     }
193     
194     /***
195      * @return Returns the boundaries.
196      */
197     public IQuery getBoundaries() {
198         return (IQuery) myBoundaries;
199     }
200     /***
201      * @param theBoundaries The boundaries to set.
202      * 
203      * @hibernate.property not-null="false" type="serializable"
204      */
205     public void setBoundaries( IQuery theBoundaries ) {
206         if ( theBoundaries != null ) {
207             assert theBoundaries instanceof Serializable;    
208         }
209         myBoundaries = (Serializable) theBoundaries;
210     }
211     
212     /***
213      * @return The <code>IChunk</code> this chunk field maps to.
214      */
215     public IChunk toChunk() {
216         return new Chunk( 
217                 getHibernateId(), 
218                 getVolatility(), 
219                 TimestampUtils.timestampToDate( getLastUpdateTime() ), 
220                 TimestampUtils.timestampToDate( getCacheTime() ), 
221                 TimestampUtils.timestampToDate( getLastAccessTime() ), 
222                 (CacheReasonEnum[]) getReasons().toArray( new CacheReasonEnum[ getReasons().size() ] ) , 
223                 getBoundaries() );
224     }
225     
226 }